﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Models;
namespace AGVControlSystemPro
{
    public partial class FrmManualControl : Form
    {
        public ServerSend objServerSend; //根据委托创建委托对象
        public FrmManualControl()
        {
            InitializeComponent();
            //AGV下拉框数据加载
            this.cboAGV.DataSource = new BLL.AGVInfoManager().GetAGVInfo("1");
            this.cboAGV.DisplayMember = "AGVName";
            this.cboAGV.ValueMember = "IP";
            //指令下拉框数据加载
            this.cboOrder.DataSource = new BLL.OrderListManager().GetAllOrderList();
            this.cboOrder.DisplayMember = "CMDName";
            this.cboOrder.ValueMember = "CMD";
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.cboAGV.SelectedIndex == -1)
            {
                if (CommonMethods.LanguageId == 3) MessageBox.Show("選択してくださいAGV", "情報のヒント");
                else MessageBox.Show("请选择需要控制的AGV", "调试提示");
                return;
            }
            if (this.cboOrder.SelectedIndex == -1)
            {
                if (CommonMethods.LanguageId == 3) MessageBox.Show("操作コマンドを選択してください", "情報のヒント");
                else MessageBox.Show("请选择操作指令", "调试提示");
                return;
            }
            if(this.txtData.Text.Trim().Length ==0)
            {
                if (CommonMethods.LanguageId == 3) MessageBox.Show("操作データを入力してください", "情報のヒント");
                else MessageBox.Show("请输入操作数据", "调试提示");
                this.txtData.Focus();
                return;
            }
            if (!Common.DataValidate.IsPositiveIntegerAndZero(this.txtData.Text.Trim()))
            {
                if (CommonMethods.LanguageId == 3) MessageBox.Show("データの位置は正の整数でなければなりません", "情報のヒント");
                else MessageBox.Show("数据位必须为正整数", "调试提示");
                this.txtData.Focus();
                return;
            }
            #endregion
           
            //数据封装
             OrderList objOrderList = new OrderList()
            {
                CMD =Convert.ToInt32( this.cboOrder.SelectedValue),
                Data = Convert.ToInt32(this.txtData.Text.Trim())
            };
            //后台数据访问
             objServerSend(this.cboAGV.SelectedValue.ToString(), objOrderList);
        }

        private void FrmManualControl_FormClosed(object sender, FormClosedEventArgs e)
        {
            FrmMain.objFrmManualControl = null;
        }

        private void FrmManualControl_Load(object sender, EventArgs e)
        {

        }
    }
}
